﻿@{
    ViewBag.Title = "资讯信息";
    Layout = "~/Views/Shared/_Index.cshtml";
}


<script>
    $(function () {
        initGridList();
    });

    //初始化列表
    function initGridList() {
        var $gridList = $("#gridList");

        $gridList.dataGrid({
            url: "/Topic/Article/GetGridJson",
            height: 630,
            colModel: [
                {
                    label: '资讯Id',
                    name: 'Id',
                    hidden: true,
                    width: 150
                },
                {
                    label: '资讯标题',
                    name: 'Title',
                    width: 300
                },
                {
                    label: '资讯类型',
                    name: 'Type',
                    width: 150
                },
                {
                    label: '所属栏目',
                    name: 'Class',
                    width: 130
                },
                {
                    label: '资讯来源',
                    name: 'Source',
                    width: 130
                },
                {
                    label: '资讯显示时间',
                    name: 'Time',
                    width: 130
                },
                {
                    label: '是否首页推荐',
                    name: 'IsHomeRecommendDesc',
                    width: 130
                },
                {
                    label: '审核状态',
                    name: 'StateDesc',
                    width: 130
                },
                {
                    label: '是否热门推荐',
                    name: 'IsHotDesc',
                    width: 130
                },
                {
                    label: '推荐城市',
                    name: 'RecommendCity',
                    width: 130
                },
                {
                    label: '是否专题',
                    name: 'IsSpecialDesc',
                    width: 130
                },
                {
                    label: '操作',
                    name: 'Id',
                    width: 320,
                    align: 'center',
                    formatter: function (cellvalue, options, rowObject) {
                        return '<div class="btn-group btn-group-xs" style="margin-top:5px;">' +
                            '   <button type="button" class="btn btn-link" onclick="btn_edit(\'' +
                            cellvalue +
                            '\', 0)">编辑</button>' +
                            '   <button type="button" class="btn btn-link" onclick="btn_del(\'' +
                            cellvalue +
                            '\')">删除</button>' +
                            '</div>';
                    }
                },
                { label: '', name: 'Id', hidden: true }
            ],
            pager: "#gridPager",
            viewrecords: true,
            multiselect: false,
            sortname: 'F_Id',
            ondblClickRow: function (rowid, iRow, iCol, e) {
                showDetailDialogBox(e);
            }
        });
    }

    //编辑
    function edit(id, title, mark) {
        var opt = {
            id: "editForm",
            title: title,
            url: "/Topic/Article/Form?keyValue=" + id,
            width: "1000px",
            height: "800px"
        };

        if (mark == 'detail') {
            $.extend(opt,
                {
                    btn: null
                });
        } else {
            $.extend(opt,
                {
                    callBack: function (iframeId) {
                        top.frames[iframeId].submitForm();
                    }
                });
        }

        $.modalOpen(opt);
    }

    //添加
    function btn_add() {
        edit('', '新建-资讯信息管理', 'add');
    }

    //编辑
    function btn_edit(id) {
        edit(id, '编辑-资讯信息管理', 'edit');
    }

    ////删除
    //function btn_detele(id) {
    //    $.modalConfirm('确定删除吗？',
    //        function (flag) {
    //            if (flag) {
    //                $.submitForm({
    //                    url: "/WorkFlowSetting/FlowManage/DeteleWorkFlow?keyValue=" + id,
    //                    success: function (data) {
    //                        $.currentWindow().$("#gridList").trigger("reloadGrid");
    //                    }
    //                });
    //            }
    //        });
    //}

    //显示详情对话框
    function showDetailDialogBox(e) {
        var rowobj = $(e.currentTarget).jqGridRowValue();

        if (rowobj.Id) {
            edit(rowobj.Id, '详情-流程', 'detail');
        } else {
            $.modalAlert("请选中行数据！", "warning");
        }
    }

</script>
<style type="text/css">
    .topPanel .search .input-group .form-control {
        padding: 4px 5px !important;
        height: 22px !important;
        margin: 0 10px !important;
        width: 80%;
    }

    .topPanel {
        height: 125px !important;
    }

        .topPanel .search table td {
            height: 30px;
            line-height: 30px;
        }

    .select2-container--default .select2-selection--single .select2-selection__rendered {
        color: #999 !important;
    }

    .checkbox, .radio {
        margin-top: 10px !important;
    }
</style>

<div style="height:100%;">
    <div class="toolbar" style="width:25%;float:right; text-align:right;">
        <div class="btn-group">
            <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
        </div>
        <div class="btn-group">
            <a id="NF-add" authorize="yes" class="btn btn-primary dropdown-text" onclick="btn_add()"><i class="fa fa-eraser"></i>新建资讯信息</a>
        </div>
    </div>
    <div style="width:75%;">
        <table class="form">
            <tr>
                <td class="formValue" style="margin: 0 10px;">
                    <input id="txt_keyword" type="text" class="form-control" placeholder="标题名称">
                </td>
                <td class="formValue">
                    <select id="F_Types" name="F_Types" class="form-control">
                        <option value="">==请选资讯类型==</option>
                    </select>
                </td>
                <td class="formValue">
                    <select id="F_Class" name="F_Class" class="form-control">
                        <option value="">==请选择所属栏目==</option>
                    </select>
                </td>
                <td class="formValue">
                    <select id="F_Source" name="F_Source" class="form-control">
                        <option value="">==请选择资讯来源==</option>
                    </select>
                </td>
                <td class="formValue">
                    <select id="F_State" name="F_State" class="form-control">
                        <option value="">==请选择审核状态==</option>
                    </select>
                </td>
            </tr>
            @*<tr>
                <td class="formValue">
                    <select id="site_type" name="site_type" class="form-control"></select>
                </td>
                <td class="formValue">
                    <select id="through_three_areas" name="through_three_areas" class="form-control required">
                        <option value="">==请选择落位区域==</option>
                        <option value="室内">室内</option>
                        <option value="室外">室外</option>
                        <option value="半开放式">半开放式</option>
                    </select>
                </td>
                <td class="formValue" style="margin: 0 10px;">
                    <input id="txt_min_area" style="width:48%;float:left;" type="text" class="form-control" placeholder="最小面积-">
                    <input id="txt_max_area" style="width:48%;float:right;" type="text" class="form-control" placeholder="+最大面积">
                </td>
                <td class="formValue" style="margin: 0 10px;">
                    <input id="txt_min_inner_price" style="width:48%;float:left;" type="text" class="form-control" placeholder="最小单价-">
                    <input id="txt_max_inner_price" style="width:48%;float:right;" type="text" class="form-control" placeholder="+最大单价">
                </td>
                <td class="formValue">
                    <input id="height" type="text" style="width:48%;float:left;" class="form-control" placeholder="层高" />
                    <input id="txt_max_seating_capacity" style="width:48%;float:right;" type="text" class="form-control" placeholder="最大容纳人数-" />
                </td>
            </tr>*@
            <tr>
                @*<td class="formValue" style="padding-left: 10px;" colspan="4">
            <div id="state_horizon" class="btn-group">
                <a class="btn btn-default active" data-value="1">上线</a>
                <a class="btn btn-default" id="xiaxian" data-value="0">下线</a>
                <a class="btn btn-default" id="shenhezhong" data-value="2">审核中</a>
                <a class="btn btn-default" id="butongguo" data-value="3">不通过</a>
                <a class="btn btn-default" id="daishangxian" data-value="4">待上线</a>
            </div>
        </td>*@
                <td class="formValue">
                    <select id="F_RecCity" name="F_RecCity" class="form-control">
                        <option value="">==请选择城市==</option>
                    </select>
                </td>
                <td class="formValue" style="text-align:right">
                    <div class="input-group">
                        <button id="btn_search" type="button" class="btn  btn-primary" style="padding:0 20px">按条件筛选</button>
                    </div>
                </td>
            </tr>
        </table>
    </div>
</div>

@*<div class="zdyPanel">
        <div class="zdyBar" style="float:left;white-space:nowrap;width:50%;">
            <div class="search">
                <table class="form" style="width:100%;">
                    <tr>
                        <td class="formValue">
                            <div class="input-group" style="width:100%;">
                                <input type="text" id="F_UserName" class="form-control textValue" placeholder="请输申请姓名" />
                                <span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span>
                                <input type="hidden" name="hd_F_UserName" id="hd_F_UserName" value="" />
                            </div>
                        </td>
                        <td class="formValue">
                            <select id="F_ApplyType" name="F_ApplyType" class="form-control selectbox">
                                <option value="">==请选择审核类型==</option>
                            </select>
                        </td>
                        <td class="formValue">
                            <input type="text" id="F_CheckDate" name="F_CheckDate" class="form-control input-wdatepicker required" onfocus="WdatePicker()" placeholder="请输入申请时间" />
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3">
                            <div id="state_horizon" class="btn-group">
                                <a class="btn btn-default active" data-value="">全部</a>
                                <a class="btn btn-default" data-value="1">审核通过</a>
                                <a class="btn btn-default" data-value="0">驳回</a>
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div class="zdyBar" style="float: right; padding-top: 5px; white-space: nowrap; width: 50%;">
            <div style="float: right;">
                <div class="btn-group">
                    <a class="btn btn-primary" onclick="$.reload()">
                        <span class="glyphicon glyphicon-refresh"></span>
                    </a>
                </div>
                <div class="btn-group">
                    <a class="btn btn-primary" onclick="btn_add()">
                        <i class="fa fa-eraser">新建资讯信息</i>
                    </a>
                </div>
            </div>
        </div>
    </div>*@
<div class="zdyGirdPanel">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>


<script>
    var dictionaryData;

    $(function () {
        initDictionryData();
        initControl();
    });

    //初始化字典数据
    function initDictionryData() {
        $.ajax({
            url: "/Topic/Article/GetIndexItemsJson",
            dataType: "json",
            async: false,
            success: function (data) {
                dictionaryData = data;
            }
        });
    }

    //初始化控件
    function initControl() {
        $("#F_Source,#F_Class,#F_State").select2();

        //$multipleSelectControls.bindSelect({
        //    placeholder: "请选择相关内容",
        //    multiple: true
        //});

        var spaces = dictionaryData.spaces;
        for (var i = 0; i < spaces.length; i++) {
            $("#F_SpaceId").append("<option value='" + spaces[i].Key + "'>" + spaces[i].Value + "</option>");
        }

        $("#F_Types").bindSelect({
            url: "/Topic/Article/GetIndexArticleTypesTreeSelectJson",
            id: "extend"
        });

        var banners = dictionaryData.banners;
        for (var i = 0; i < banners.length; i++) {
            $("#F_Class").append("<option value='" + banners[i].F_ItemCode + "'>" + banners[i].F_ItemName + "</option>");
        }

        var sources = dictionaryData.sources;
        for (var i = 0; i < sources.length; i++) {
            $("#F_Source").append("<option value='" + sources[i].F_ItemCode + "'>" + sources[i].F_ItemName + "</option>");
        }

        var auditStates = dictionaryData.auditStates;
        for (var i = 0; i < auditStates.length; i++) {
            $("#F_State").append("<option value='" + auditStates[i].F_ItemCode + "'>" + auditStates[i].F_ItemName + "</option>");
        }



        $("#F_RecCity").bindSelect({
            url: "/ClientManager/ClientInfos/GetAllCitys",
            search: true,
            id: "F_EnCode",
            text: "F_FullName",
        });

        $("#F_SpaceId").select2({ multiple: false });

        $('#btn_search').click(function() {
            reloadGridList();
        });
    }



    function reloadGridList() {
        var $gridList = $("#gridList");
        var queryJson = {
            F_Title: $('#txt_keyword').val(),
            F_Types: $("#F_Types").val() == '0' ? '' : $("#F_Types").val(),
            F_Class: $("#F_Class").val(),
            F_Source: $("#F_Source").val(),
            F_State: $("#F_State").val(),
            F_RecCity: $("#F_RecCity").val(),
        };
        $gridList.jqGrid('setGridParam', {
            postData: { queryJson: JSON.stringify(queryJson) },
        }).trigger('reloadGrid');
    }
</script>